﻿using HLStock.Common;
using System.Data;

namespace HLStock.DBAccess
{
    public class SqlCostRec : IDisposable
    {
        public static SqlCostRec Start(IDbCommand cmd)
        {
            return new SqlCostRec(cmd);
        }

        DateTime startDt;
        IDbCommand command;
        public SqlCostRec(IDbCommand cmd)
        {
            startDt = DateTime.Now;
            command = cmd;
        }

        public void Dispose()
        {
            command.Dispose();
            var cost = (DateTime.Now - startDt).TotalMicroseconds;
            MyLogger.Sql("EXEC SQL={0} COST={1}ms", command.CommandText, cost);
        }
    }
}
